# Avaliação de Desempenho de Sistemas

setwd("~/Projects/avaliacao-desempenho/statistic")
cria_data = read.table('data/cria-files.txt')[,1]
extrai_data = read.table('data/extrai-files.txt')[,1]

analyze <- function(data, config) {

  #plot boxchart
  #png(paste('summary/charts/', config, '-box', '.png', sep=""))
  png(paste('summary/charts/', 'box-', config, '.png', sep=""))
  boxplot(data, ylab="Time(ms)")

  #plot histogram
  #png(paste('summary/charts/', config, '-hist', '.png', sep=""))
  png(paste('summary/charts/', 'hist-', config, '.png', sep=""))
  hist(data)
  dev.off()

  #get data summary
  sink(paste('summary/', config, '.txt', sep=""))
  #cat('Summary:')
  #cat("\n")

  #cat(capture.output(summary(data))[1])
  #cat("\n")

  #cat(capture.output(summary(data))[2])
  #cat("\n")

  cat('Range:')
  cat(range(data))
  cat("\n")

  cat('Min:')
  cat(min(data))
  cat("\n")

  cat('Max:')
  cat(max(data))
  cat("\n")

  cat('Median:')
  cat(median(data))
  cat("\n")

  cat('Mean:')
  cat(mean(data))
  cat("\n")

  cat('1st Qu:')
  cat(max(data))
  cat("\n")

  cat('3nd Qu:')
  cat(max(data))
  cat("\n")

  cat('IQR:')
  cat(IQR(data))
  cat("\n")

  cat('Variance:')
  cat(var(data))
  cat("\n")

  cat('Standard Deviation:')
  cat(sd(data))
  dev.off()
  sink()
}

for(i in extrai_data) {
  times = read.table(paste('data/extrai/', i, sep=""))[,1]
  analyze(times, i)
}

for(i in cria_data) {
  times = read.table(paste('data/cria/', i, sep=""))[,1]
  analyze(times, i)
}
